import abc


class Base(abc.ABC):
    @abc.abstractmethod
    def my_protocol(self):
        """自定义协议"""

    @classmethod
    def __subclasshook__(cls, subclass):
        print(cls)
        if cls is Base:
            if any("my_protocol" in B.__dict__ for B in subclass.__mro__):
                return True
        return NotImplemented


class SubBase(Base, abc.ABC):
    pass


class NotAbstract:
    def my_protocol(self):
        pass


print(issubclass(int, int))  # True，所以下面的行为应当一致
print(issubclass(SubBase, SubBase))  # 返回NotImplemented，Python自动解析为True
print(issubclass(SubBase, Base))  # True
print(issubclass(NotAbstract, SubBase))  # False
print(issubclass(NotAbstract, Base))  # True
# print(isinstance(SubBase(), SubBase))  抽象基类未实现，不能实例化
